home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / knumvalidator.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.3 KB  |  213 lines

  1. /**********************************************************************
  2. **
  3. ** $Id: knumvalidator.h 469215 2005-10-10 13:47:50Z lukas $
  4. **
  5. ** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com>
  6. ** Copyright (C) 2002 Marc Mutz <mutz@kde.org>
  7. **
  8. ** This library is free software; you can redistribute it and/or
  9. ** modify it under the terms of the GNU Library General Public
  10. ** License as published by the Free Software Foundation; either
  11. ** version 2 of the License, or (at your option) any later version.
  12. **
  13. ** This library is distributed in the hope that it will be useful,
  14. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. ** Library General Public License for more details.
  17. **
  18. ** You should have received a copy of the GNU Library General Public
  19. ** License along with this library; if not, write to the Free
  20. ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef __KNUMVALIDATOR_H
  25. #define __KNUMVALIDATOR_H
  26.  
  27. #include <qvalidator.h>
  28.  
  29. #include <kdelibs_export.h>
  30.  
  31. class QWidget;
  32. class QString;
  33.  
  34. /**
  35.  * QValidator for integers.
  36.  
  37.   This can be used by QLineEdit or subclass to provide validated
  38.   text entry.  Can be provided with a base value (default is 10), to allow
  39.   the proper entry of hexadecimal, octal, or any other base numeric data.
  40.  
  41.   @author Glen Parker <glenebob@nwlink.com>
  42.   @version 0.0.1
  43. */
  44. class KDEUI_EXPORT KIntValidator : public QValidator {
  45.  
  46.   public:
  47.     /**
  48.       Constuctor.  Also sets the base value.
  49.     */
  50.     KIntValidator ( QWidget * parent, int base = 10, const char * name = 0 );
  51.     /**
  52.      * Constructor.  Also sets the minimum, maximum, and numeric base values.
  53.      */
  54.     KIntValidator ( int bottom, int top, QWidget * parent, int base = 10, const char * name = 0 );
  55.     /**
  56.      * Destructs the validator.
  57.      */
  58.     virtual ~KIntValidator ();
  59.     /**
  60.      * Validates the text, and return the result.  Does not modify the parameters.
  61.      */
  62.     virtual State validate ( QString &, int & ) const;
  63.     /**
  64.      * Fixes the text if possible, providing a valid string.  The parameter may be modified.
  65.      */
  66.     virtual void fixup ( QString & ) const;
  67.     /**
  68.      * Sets the minimum and maximum values allowed.
  69.      */
  70.     virtual void setRange ( int bottom, int top );
  71.     /**
  72.      * Sets the numeric base value.
  73.      */
  74.     virtual void setBase ( int base );
  75.     /**
  76.      * Returns the current minimum value allowed.
  77.      */
  78.     virtual int bottom () const;
  79.     /**
  80.      * Returns the current maximum value allowed.
  81.      */
  82.     virtual int top () const;
  83.     /**
  84.      * Returns the current numeric base.
  85.      */
  86.     virtual int base () const;
  87.  
  88.   private:
  89.     int _base;
  90.     int _min;
  91.     int _max;
  92.  
  93. };
  94.  
  95. class KFloatValidatorPrivate;
  96.  
  97. /**
  98.  \brief QValidator for floating point entry (Obsolete)
  99.  
  100.   @obsolete Use KDoubleValidator
  101.  
  102.   Extends the QValidator class to properly validate double numeric data.
  103.   This can be used by QLineEdit or subclass to provide validated
  104.   text entry.
  105.  
  106.   @author Glen Parker <glenebob@nwlink.com>
  107.   @version 0.0.1
  108. */
  109. class KDEUI_EXPORT KFloatValidator : public QValidator {
  110.  
  111.   public:
  112.     /**
  113.      * Constructor.
  114.      */
  115.     KFloatValidator ( QWidget * parent, const char * name = 0 );
  116.     /**
  117.      * Constructor.  Also sets the minimum and maximum values.
  118.      */
  119.     KFloatValidator ( double bottom, double top, QWidget * parent, const char * name = 0 );
  120.     /**
  121.      * Constructor.  Sets the validator to be locale aware if @p localeAware is true.
  122.      */
  123.     KFloatValidator ( double bottom, double top, bool localeAware, QWidget * parent, const char * name = 0 );
  124.     /**
  125.      * Destructs the validator.
  126.      */
  127.     virtual ~KFloatValidator ();
  128.     /**
  129.      * Validates the text, and return the result. Does not modify the parameters.
  130.      */
  131.     virtual State validate ( QString &, int & ) const;
  132.     /**
  133.      * Fixes the text if possible, providing a valid string. The parameter may be modified.
  134.      */
  135.     virtual void fixup ( QString & ) const;
  136.     /**
  137.      * Sets the minimum and maximum value allowed.
  138.      */
  139.     virtual void setRange ( double bottom, double top );
  140.     /**
  141.      * Returns the current minimum value allowed.
  142.      */
  143.     virtual double bottom () const;
  144.     /**
  145.      * Returns the current maximum value allowed.
  146.      */
  147.     virtual double top () const;
  148.     /**
  149.      * Sets the validator to be locale aware if @p is true. In this case, the
  150.      * character KLocale::decimalSymbol() from the global locale is recognized
  151.      * as decimal separator.
  152.      */
  153.     void setAcceptLocalizedNumbers(bool b);
  154.     /**
  155.      * Returns true if the validator is locale aware.
  156.      * @see setAcceptLocalizedNumbers().
  157.      */
  158.     bool acceptLocalizedNumbers() const;
  159.  
  160.  private:
  161.     double _min;
  162.     double _max;
  163.  
  164.     KFloatValidatorPrivate *d;
  165. };
  166.  
  167. /**
  168.    @short A locale-aware QDoubleValidator
  169.  
  170.    KDoubleValidator extends QDoubleValidator to be
  171.    locale-aware. That means that - subject to not being disabled -
  172.    KLocale::decimalSymbol(), KLocale::thousandsSeparator()
  173.    and KLocale::positiveSign() and KLocale::negativeSign()
  174.    are respected.
  175.  
  176.    @author Marc Mutz <mutz@kde.org>
  177.    @see KIntValidator
  178.    @since 3.1
  179. **/
  180.  
  181. class KDEUI_EXPORT KDoubleValidator : public QDoubleValidator {
  182.   Q_OBJECT
  183.   Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
  184. public:
  185.   /** Constuct a locale-aware KDoubleValidator with default range
  186.       (whatever QDoubleValidator uses for that) and parent @p
  187.       parent */
  188.   KDoubleValidator( QObject * parent, const char * name=0 );
  189.   /** Constuct a locale-aware KDoubleValidator for range [@p bottom,@p
  190.       top] and a precision of @p decimals decimals after the decimal
  191.       point.  */
  192.   KDoubleValidator( double bottom, double top, int decimals,
  193.             QObject * parent, const char * name=0 );
  194.   /** Destructs the validator.
  195.    */
  196.   virtual ~KDoubleValidator();
  197.  
  198.   /** Overloaded for internal reasons. The API is not affected. */
  199.   virtual QValidator::State validate( QString & input, int & pos ) const;
  200.  
  201.   /** @return whether localized numbers are accepted (default: true) */
  202.   bool acceptLocalizedNumbers() const;
  203.   /** Sets whether to accept localized numbers (default: true) */
  204.   void setAcceptLocalizedNumbers( bool accept );
  205.  
  206. private:
  207.   typedef QDoubleValidator base;
  208.   class Private;
  209.   Private * d;
  210. };
  211.  
  212. #endif
  213.